package blackhouse_dao;

import java.sql.ResultSet;
import java.sql.SQLException;

public class login_dao extends jdbc_dao
{
	public int login(String id, String pwd, String ls) throws SQLException
	{
		int num = -1;
		if (ls.equals("1"))
		{
			String sql = "select * from login where code='" + id
					+ "' and pwd='" + pwd + "'";
			ResultSet RS = query(sql);
			while (RS.next())
			{
				num = RS.getInt("stateid");
			}
			close(conn, st, RS);
			return num;
		} else
		{
			String sql = "INSERT INTO login(code, pwd,stateid) SELECT '"
					+ id
					+ "', '"
					+ pwd
					+ "', '"
					+ ls
					+ "' FROM DUAL WHERE NOT EXISTS(SELECT code FROM login WHERE code = '"
					+ id + "')";
			int RS = update(sql);
			return RS;
		}
	}
}
